<template>
    <div>
        <el-form ref="form" :model="form" label-width="70px">
                          <el-form-item label="用户名">
                <el-input v-model="form.username"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="form.password"></el-input>
            </el-form-item>
            <el-form-item label="创建时间">
                 <el-date-picker type="datetime" value-format="timestamp" v-model="form.gmtCreate"
                                 placeholder="选择时间"></el-date-picker>
            </el-form-item>
            <el-form-item label="更新时间">
                 <el-date-picker type="datetime" value-format="timestamp" v-model="form.gmtUpdate"
                                 placeholder="选择时间"></el-date-picker>
            </el-form-item>
        </el-form>
        <div class="footer">
             <span slot="footer" class="dialog-footer">
                <el-button @click="cancel">取 消</el-button>
                <el-button type="primary" @click="update">确 定</el-button>
            </span>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'admin-update',
        props: {
            tId: Number,
            tForm: Object
        },
        data() {
            return {
                updateUrl: '/user/restpage/userLogin/update', //更新地址
                showUrl: '/user/restpage/userLogin/get', //数据地址
                form: this.tForm
            }
        },
        watch: {
            tForm(v) {
                this.form = v;
            }
        },
        methods: {
            showById(){
                if (this.tId && this.tId !== -1 && this.tId !== 0) {
                    this.$http.get(this.showUrl, {
                        id: this.tId
                    }).then(res => {
                        this.form = res;
                    });
                }
            },
            //更新
            update() {
                this.$http.post(this.updateUrl, this.form).then(res => {
                    if (res.code === 200) {
                        this.$message.success(res.msg);
                    }
                    this.$emit('closeWin', true);
                });
            },
            cancel() {
                this.$emit('closeWin', false);
            }
        }
    };
</script>

<style scoped>
    .footer {
        text-align: center;
    }
</style>